package com.shaolei.image_transfer;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import javax.imageio.ImageIO;

public class Image_tranfer {
	public static BufferedImage read_image(String name){
		BufferedImage img = null;
		try {
		    img = ImageIO.read(new File(name));
		} catch (IOException e) {
		}
		return img;
	}
	public static void main(String[] args){
		String image_name= "images/Tsukuba2_L.bmp";
		BufferedImage image= Image_tranfer.read_image(image_name);
		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			ImageIO.write(image, "bmp", out);
			byte[] myArray= out.toByteArray();
//			System.out.println(Arrays.toString(myArray));
			System.out.println(myArray.length);
			ByteArrayInputStream in = new ByteArrayInputStream(myArray); 
			BufferedImage  image2 = ImageIO.read( in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
